/**
 * 
 */
package edu.gtcfla.km.platform.appmodules.web;

import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.vsg.common.web.json.ListResult;
import org.vsg.security.annotation.RegisterRequestPermissionStrategy;

import edu.gtcfla.km.core.ApplicationConstant;
import edu.gtcfla.km.platform.service.SystemUserManager;
import edu.gtcfla.km.platform.vo.SystemUserVO;

/**
 * @author Bill Vison
 *
 */
@Controller(value="systemUserController")
@Lazy
@RequestMapping(ApplicationConstant.DATA_RERESOURCE)
public class UserController {

	private final static Logger logger = LoggerFactory.getLogger(UserController.class);

	@Autowired(required = false)
	private SystemUserManager usMsnager;

	
	
	@RequiresUser	
	@RegisterRequestPermissionStrategy(
		value = "availableusers.json",
		skipCheck = true
	)	
	@RequestMapping(value = "/availableusers.json")
	public @ResponseBody ListResult findAvailableUsers(String currentUserId,
			HttpServletResponse response) throws Exception {

		Set<SystemUserVO>  users = usMsnager.findAllAvaiableSystemUser( currentUserId );

		ListResult lr = new ListResult();
		lr.setRows(users);
		lr.setResults((int) users.size());

		return lr;

	}

	
	@RequiresUser	
	@RegisterRequestPermissionStrategy(
		value = "staffusers.json",
		skipCheck = true
	)	
	@RequestMapping(value = "/staffusers.json")
	public @ResponseBody ListResult findAllStaffUsers(String currentUserId,
			HttpServletResponse response) throws Exception {
		
		Set<SystemUserVO>  users = usMsnager.findAllAvaiableSystemUser( currentUserId );

		ListResult lr = new ListResult();
		lr.setRows(users);
		lr.setResults((int) users.size());

		return lr;

	}
	
	
}
